package com.cheer.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cheer.entity.MallComplaintEntity;
import com.cheer.entity.OaLearnClassEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cheer.enums.OaLearnClassTypeEnum;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * 部门表
 *
 * @author cheer
 */
@Mapper
@Repository
public interface OaLearnClassDao extends BaseMapper<OaLearnClassEntity> {

    default List<OaLearnClassEntity> selectListByPid(Integer id) {
        return selectList(new QueryWrapper<OaLearnClassEntity>()
                .eq("pid", id));
    }

    default IPage<OaLearnClassEntity> selectPage(Integer pageNum, Integer pageSize) {
        return selectPage(new Page<>(pageNum, pageSize), Wrappers.emptyWrapper());
    }

    default IPage<OaLearnClassEntity> selectPageByPath(Integer pageNum, Integer pageSize, Integer id) {
        return selectPage(new Page<>(pageNum, pageSize), new QueryWrapper<OaLearnClassEntity>()
                .eq("pid", id)
                .or()
                .eq("id", id)
                .orderByAsc("path")
                .orderByAsc("id"));
    }

    default OaLearnClassEntity selectOneByPid(Integer id) {
        return selectOne(new QueryWrapper<OaLearnClassEntity>()
                .eq("pid", id)
                .last("limit 1"));
    }

    default IPage<OaLearnClassEntity> selectPageByPid(Integer pageNum, Integer pageSize, Integer pid) {
        return selectPage(new Page<>(pageNum, pageSize), new QueryWrapper<OaLearnClassEntity>()
                .eq("id", pid)
                .or()
                .eq("pid", pid)
                .orderByAsc("id"));
    }

    default List<OaLearnClassEntity> selectListByPath(Integer id, String path) {
        return selectList(new QueryWrapper<OaLearnClassEntity>()
                .eq("id", id)
                .or()
                .likeRight("path", path)
                .orderByAsc("id"));
    }

    default List<OaLearnClassEntity> selectListByIdAndPid(Integer pid) {
        return selectList(new QueryWrapper<OaLearnClassEntity>()
                .eq("id", pid)
                .or()
                .eq("pid", pid)
                .orderByAsc("id"));
    }

    default void updatePathByIds(String path, List<Integer> ids) {
        OaLearnClassEntity oaLearnClassEntity = new OaLearnClassEntity()
                .setPath(path);
        update(oaLearnClassEntity, new QueryWrapper<OaLearnClassEntity>()
            .in("id", ids));
    }

    default List<OaLearnClassEntity> listSchool(){

        QueryWrapper<OaLearnClassEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().in(OaLearnClassEntity::getType,
                OaLearnClassTypeEnum.CITY.getCode(),
                OaLearnClassTypeEnum.COLLEGE.getCode());

        return selectList(queryWrapper);
    }

    default List<OaLearnClassEntity> listSchool(Integer type){

        QueryWrapper<OaLearnClassEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().in(OaLearnClassEntity::getType, type);

        return selectList(queryWrapper);
    }
}
